//
//  CrazyChatCustomTextCell.m
//  webSocket
//
//  Created by 马军凯 on 2019/2/18.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatCustomTextCell.h"

@interface CrazyChatCustomTextCell ()

@property (nonatomic, strong) UIImageView *customHeadImageView; //头像
@property (nonatomic, strong) UIView *customTextBackView; //背景
@property (nonatomic, strong) UIImageView *customTextBackImageView; //背景图片
@property (nonatomic, strong) UILabel *customTextLabel; //消息

@end

@implementation CrazyChatCustomTextCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *identifier = CrazyChatCustomTextIdentifier;
    
    //缓存中取
    CrazyChatCustomTextCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    //创建
    if (!cell) {
        cell = [[CrazyChatCustomTextCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor clearColor];
        //头像
        self.customHeadImageView = [[UIImageView alloc] init];
        self.customHeadImageView.frame = CGRectMake(15, 10, 40, 40);
        [self.contentView addSubview:self.customHeadImageView];
        //背景
        self.customTextBackView = [[UIView alloc] init];
        self.customTextBackView.frame = CGRectMake(60, 10, CRAZY_SCREEN_WIDTH - 120, 40);
        [self.contentView addSubview:self.customTextBackView];
        //背景图片
        self.customTextBackImageView = [[UIImageView alloc] init];
        self.customTextBackImageView.image = [[UIImage imageNamed:@"Crazy_chat_leftPic@2x.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(23, 15, 7, 15) resizingMode:UIImageResizingModeStretch];
        [self.customTextBackView addSubview:self.customTextBackImageView];
        //label
        self.customTextLabel = [[UILabel alloc] init];
        self.customTextLabel.textColor = CRAZY_RGBR(33);
        self.customTextLabel.font = [UIFont systemFontOfSize:14];
        self.customTextLabel.numberOfLines = 0;
        [self.customTextBackView addSubview:self.customTextLabel];
    }
    return self;
}

//赋值
- (void)setCellValueWithHeadURL:(NSString *)headURL content:(NSMutableAttributedString *)content {
    //头像
    [self.customHeadImageView sd_setImageWithURL:[NSURL URLWithString:headURL] placeholderImage:CRAZY_DEFAULT_HEADIMAGE];
    //聊天
    self.customTextLabel.attributedText = content;
    CGSize maxSize = CGSizeMake(CRAZY_SCREEN_WIDTH - 120 - 20, 9999);
    CGSize size = [self.customTextLabel sizeThatFits:maxSize];
    self.customTextLabel.frame = CGRectMake(12, 10, size.width, size.height);
    //背景
    self.customTextBackView.width = size.width + 20;
    self.customTextBackView.height = size.height + 20;
    //背景图片
    self.customTextBackImageView.frame = self.customTextBackView.bounds;
}















- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
